<?php


namespace App\Admin\Forms;


use App\Jobs\SubscribeMessageJob;
use App\Models\WxAuthentication;
use App\Models\User\WxUser;
use App\Wen\Utils\UserUtils;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;
use Illuminate\Support\Facades\Cache;

class AuthenticationForms extends Form implements LazyRenderable
{
    use LazyWidget;


    /**
     * 主题颜色.
     *
     * @var array
     */
    protected $colors = [
        'default' => '深蓝',
        'blue' => '蓝',
//        'blue-light' => '浅蓝',
//        'blue-dark'  => '深蓝',
        'green' => '绿',
    ];

    /**
     * 处理表单请求.
     *
     * @param array $input
     *
     * @return mixed
     */
    public function handle(array $input)
    {

        $type = $input['type'];
        $content  = _empty_default_($input['overrule_content'] ?? '', '');

        $authentication = WxAuthentication::find($input['id']);
        UserUtils::authenticate_pass($authentication, $type, $content);

        return $this->response()
            ->success('操作完成.')
            ->refresh();
    }

    /**
     * 构建表单.
     */
    public function form()
    {

        $this->hidden('id')->value($this->payload["id"]);
        $this->radio('type','操作')
            ->when(1, function (Form $form) {

            })
            ->when(2, function (Form $form) {
                $form->textarea('overrule_content', "回复内容");
            })
            ->options([
                1 => '审核通过',
                2 => '驳回',

            ])
            ->default(1);

    }
}
